package com.letoken.platform.repo.mall.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.repo.app.req.mall.CollectShopsReq;
import com.letoken.platform.repo.app.req.mall.ShopsReq;
import com.letoken.platform.repo.app.res.mall.MallCollectCategoryRes;
import com.letoken.platform.repo.app.res.mall.MallCollectShopsRes;
import com.letoken.platform.repo.app.res.mall.MallUserShopsRes;
import com.letoken.platform.repo.mall.po.AppMallCollect;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.letoken.platform.repo.mall.po.AppMallMenuConfig;
import com.letoken.platform.repo.mall.po.AppMallStatistics;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 店铺收藏表 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2023-06-30
 */
public interface AppMallCollectMapper extends BaseMapper<AppMallCollect> {



    @Select("select DISTINCT m.id,m.level from app_mall_collect c inner join app_mall_info a on c.mall_id = a.id inner join app_mall_menu_config m on a.one_category = m.id where c.user_id = #{userId} order by m.sort desc ")
    List<MallCollectCategoryRes> getCollectMenuList(@Param("userId") Integer userId);



    @Select("select 1 from app_mall_collect  where user_id = #{userId} and mall_id = #{mallId} and state = 0 limit 1")
    Integer userIsCollectMall(@Param("userId") Integer userId,@Param("mallId") Integer mallId);


    Page<MallCollectShopsRes> collectShops(@Param("page") Page<MallCollectShopsRes> page , @Param("req") CollectShopsReq req);


    @Select("select 1 from app_mall_info where id = #{mallId} and state = 1 and publish_state = 0 limit 1")
    Integer mallIsExits(@Param("mallId") Integer mallId);


    @Select("select id,state from app_mall_collect where mall_id  = #{mallId} and user_id = #{userId} limit 1")
    AppMallCollect collectIsExits(@Param("mallId") Integer mallId,@Param("userId") Integer userId);

    void updateBatchById(@Param("list")List<AppMallCollect> list);
    @Update("update app_mall_collect set state = 1 where mall_id = #{mallId} and user_id = #{userId} ")
    int updateByMallId(@Param("mallId") Integer mallId ,@Param("userId") Integer userId);


    @Select("select mall_id as mallId , IFNULL(count(*),0) as count  from app_mall_collect where  state = 0   group by mall_id ")
    List<HashMap<String,Object>> mallCollect();


}
